home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 13288 / 13288.xpi / content / preference.js < prev    next >
Text File  |  2010-01-24  |  10KB  |  229 lines

  1. const DiskCacheBranch = "browser.cache.disk.parent_directory";
  2.  
  3. var stmPref = {
  4.     gPrefs: Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch),
  5.     gBlockHotkey: "",  //keycode+key+modifiers
  6.     gPageLockHotkey: "",
  7.     gBosskeyHidekey: "",
  8.     gBosskeyShowkey: "",
  9.     gDiskCacheDefaultDir: false,
  10.     gCacheDelUserBranch: false,
  11.  
  12.     onLoad: function() {
  13.         var b = this.gPrefs.getBoolPref("extensions.stm.pagelock.enable");
  14.         document.getElementById("b.pagelock.enable").setAttribute("disabled", b==true?"false":"true");
  15.         this.setTabColorAttribute(b);
  16.  
  17.         this.onOpenInNewTab();
  18.  
  19.         b = this.gPrefs.getBoolPref("extensions.stm.block.enable");
  20.         document.getElementById("b.block.enable").setAttribute("disabled", b==true?"false":"true");
  21.  
  22.         b = this.gPrefs.getBoolPref("extensions.stm.bosskey.enable");
  23.         document.getElementById("b.bosskey.enable").setAttribute("disabled", b==true?"false":"true");
  24.  
  25.         b = this.gPrefs.getBoolPref("browser.cache.disk.enable");
  26.         document.getElementById("b.cachedisk.enable").setAttribute("disabled", b==true?"false":"true");
  27.  
  28.         //get hotkey
  29.         this.getHotkey("pagelock.hotkey");
  30.         this.getHotkey("block.hotkey");
  31.         this.getHotkey("bosskey.hidekey");
  32.         this.getHotkey("bosskey.showkey");
  33.  
  34.         //cache
  35.         this.setCacheDirLabel();
  36.  
  37.         document.getElementById("pane1.tabbox").selectedIndex = this.gPrefs.getIntPref("extensions.stm.selectedTab");
  38.     },
  39.  
  40.     getHotkey: function(pname) {
  41.         var list = this.gPrefs.getCharPref("extensions.stm." + pname).split("|:|");
  42.         document.getElementById("e." + pname).value = list[0];
  43.     },
  44.  
  45.     setCacheDirLabel: function() {
  46.         var label = document.getElementById("diskcache.pos");
  47.         label.value = this.getCurrentCacheDir();
  48.     },
  49.  
  50.     setUserCacheDir: function(poslabel, alertlabel) {
  51.         var nsIFilePicker = Components.interfaces.nsIFilePicker;
  52.         var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  53.         fp.init(window, document.getElementById("stm.prefstringmanager").getString("diskcache.selectdir"), nsIFilePicker.modeGetFolder);
  54.         var fpShow = fp.show();
  55.         if (fpShow == nsIFilePicker.returnOK) {
  56.             document.getElementById(poslabel).value = fp.file.path + "\\Cache";
  57.             var e = document.getElementById(alertlabel);
  58.             if (fp.file.path + "\\Cache" != this.getCurrentCacheDir())
  59.                 e.hidden=false;
  60.             else 
  61.                 e.hidden=true;
  62.         }
  63.     },
  64.  
  65.     setDefaultCacheDir: function(poslabel, alertlabel) {
  66.         var ddir = this.getDefaultCacheDir();
  67.         document.getElementById(poslabel).value = ddir;
  68.         var e = document.getElementById(alertlabel);
  69.         if (ddir != this.getCurrentCacheDir())
  70.             e.hidden = false;
  71.         else
  72.             e.hidden = true;
  73.     },
  74.  
  75.     getCurrentCacheDir: function() {
  76.         var cdir;
  77.         var cache_service = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
  78.         var cvisitor = {visitDevice: function(device, aDeviceInfo) {
  79.                 if (device == "disk") {
  80.                     var des = aDeviceInfo.usageReport;
  81.                     var start = des.indexOf("<tt>") + 4;
  82.                     var stop = des.indexOf("</tt>");
  83.                     cdir = des.substring(start,stop).replace(/^\s+/g,"").replace(/\s+$/g,"");
  84.                 }
  85.         }}
  86.         cache_service.visitEntries(cvisitor);
  87.         return cdir;
  88.     },
  89.  
  90.     getDefaultCacheDir: function() {
  91.         return Components.classes["@mozilla.org/file/directory_service;1"].
  92.                              getService(Components.interfaces.nsIProperties).
  93.                              get("ProfD", Components.interfaces.nsIFile).path + "\\Cache";
  94.     },
  95.  
  96.     restartApp: function() {
  97.         this.updateCacheDir();
  98.  
  99.         var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(Components.interfaces.nsIAppStartup);
  100.         appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
  101.     },
  102.  
  103.     hideRestart: function(ename) {
  104.         document.getElementById(ename).hidden = true;
  105.     },
  106.  
  107.     updateCacheDir: function() {
  108.         var userdir = document.getElementById("diskcache.pos").value;
  109.         if (userdir == this.getCurrentCacheDir()) return;
  110.         if (userdir == this.getDefaultCacheDir())
  111.             this.gPrefs.deleteBranch(DiskCacheBranch);
  112.         else
  113.             this.gPrefs.setCharPref(DiskCacheBranch, userdir.replace(/\\Cache$/g, ""));
  114.     },
  115.  
  116.     onOK: function() {
  117.         if (this.gBlockHotkey != "")
  118.             this.gPrefs.setCharPref("extensions.stm.block.hotkey", this.gBlockHotkey);
  119.         if (this.gPageLockHotkey != "")
  120.             this.gPrefs.setCharPref("extensions.stm.pagelock.hotkey", this.gPageLockHotkey);
  121.         if (this.gBosskeyHidekey != "")
  122.             this.gPrefs.setCharPref("extensions.stm.bosskey.hidekey", this.gBosskeyHidekey);
  123.         if (this.gBosskeyShowkey != "")
  124.             this.gPrefs.setCharPref("extensions.stm.bosskey.showkey", this.gBosskeyShowkey);
  125.  
  126.         this.updateCacheDir();
  127.         this.setPane1SelectedTab();
  128.     },
  129.  
  130.     setPane1SelectedTab: function() {
  131.         this.gPrefs.setIntPref("extensions.stm.selectedTab", document.getElementById("pane1.tabbox").selectedIndex);
  132.     },
  133.  
  134.     onReset: function() {
  135.         var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  136.         var strings = document.getElementById("stm.prefstringmanager");
  137.         if(!prompts.confirm(null, null, strings.getString('prefs.onreset'))) return false;
  138.  
  139.         var count = { value : 0 };
  140.         var childList = this.gPrefs.getChildList("extensions.stm.", count);
  141.         for(var i = 0; i < count.value; i++) {
  142.             if (this.gPrefs.prefHasUserValue(childList[i])) this.gPrefs.clearUserPref(childList[i]);
  143.         }
  144.         var ffprefs = new Array("browser.tabs.loadBookmarksInBackground",
  145.                                 "browser.tabs.tabMinWidth",
  146.                                 "browser.sessionstore.max_tabs_undo",
  147.                                 "browser.tabs.loadInBackground",
  148.                                 "browser.link.open_newwindow",
  149.                                 "browser.link.open_newwindow.restriction",
  150.                                 "browser.tabs.loadDivertedInBackground",
  151.                                 "browser.tabs.closeButtons",
  152.                                 "browser.tabs.closeWindowWithLastTab",
  153.                                 "browser.cache.disk.enable",
  154.                                 "browser.cache.disk.capacity",
  155.                                 "browser.cache.disk.parent_directory",
  156.                                 "browser.cache.memory.enable",
  157.                                 "browser.cache.offline.enable",
  158.                                 "browser.cache.offline.capacity",
  159.                                 "browser.urlbar.maxRichResults"
  160.                                );
  161.         for(var i = 0; i < ffprefs.length; i++) {
  162.             if (this.gPrefs.prefHasUserValue(ffprefs[i])) this.gPrefs.clearUserPref(ffprefs[i]);
  163.         }
  164.         window.location.reload(false);
  165.     },
  166.  
  167.     syncOpenBHSInNewTab: function(value) {
  168.         this.gPrefs.setBoolPref("browser.search.openintab", value);
  169.     },
  170.  
  171.     onOpenInNewTab: function() {
  172.         var checked1 = document.getElementById("e.openURLBarInNewTab").checked;
  173.         var checked2 = document.getElementById("e.openBHSInNewTab").checked;
  174.         document.getElementById("e.newTabForeBack").disabled=!checked1 & !checked2;
  175.     },
  176.  
  177.     onPagelockEnable: function(pcheckbox) {
  178.         var b = document.getElementById("b.pagelock.enable");
  179.         b.setAttribute("disabled", !pcheckbox.checked);
  180.         this.setTabColorAttribute(pcheckbox.checked);
  181.     },
  182.  
  183.     setTabColorAttribute: function(pagelock_enable) {
  184.         var element = document.getElementById("e.pagelock.enableTabColor");
  185.         document.getElementById("e.pagelock.tabColor").disabled = pagelock_enable==true ? !element.checked : true;
  186.  
  187.         element = document.getElementById("e.pagelock.enableTabTxtColor");
  188.         document.getElementById("e.pagelock.tabTxtColor").disabled = pagelock_enable==true ? !element.checked : true;
  189.     },
  190.  
  191.     onPLEnableTabColor: function(pcheckbox) {
  192.         document.getElementById("e.pagelock.tabColor").disabled = !pcheckbox.checked;
  193.     },
  194.  
  195.     onPLEnableTabTxtColor: function(pcheckbox) {
  196.         document.getElementById("e.pagelock.tabTxtColor").disabled = !pcheckbox.checked;
  197.     },
  198.  
  199.     /* toggle toolbar button */
  200.     toggleButton: function(bname) {
  201.         var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  202.         wm.getMostRecentWindow("navigator:browser").stmM.toggleToolbarButton(bname);
  203.     },
  204.  
  205.     onBlockEnable: function(pcheckbox) {
  206.         var b = document.getElementById("b.block.enable");
  207.         b.setAttribute("disabled", !pcheckbox.checked);
  208.     },
  209.  
  210.     onBosskeyEnable: function(pcheckbox) {
  211.         var b = document.getElementById("b.bosskey.enable");
  212.         b.setAttribute("disabled", !pcheckbox.checked);
  213.     },
  214.  
  215.     changeHotkey: function(labelid) {
  216.         this.gBlockHotkey = "";
  217.         const dialog = "chrome://supertabmode/content/key.xul";
  218.         var features = "chrome,titlebar,toolbar,centerscreen,modal";
  219.         window.openDialog(dialog, "", features, labelid);
  220.     },
  221.  
  222.     onCacheDiskEnable: function(pcheckbox) {
  223.         var b = document.getElementById("b.cachedisk.enable");
  224.         b.setAttribute("disabled", !pcheckbox.checked);
  225.     },
  226.  
  227. }  //var end
  228.  
  229.